
package gui;
/*
 * this gui handel with the system maneger , all he got to do is write the user name of the 
 * client he want to block from ordering, the client will still be able to login to the system but 
 * he wont be able to commite an order
 */
import java.awt.Color;
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import client.Client;
import gui.MainSystemManger;

public class BlockCommit extends JFrame {
	private JLabel jLabelBackground = null;
	private JPanel Sub = null;
	private MainCustomer MC;
	private JButton jButtonBack = null;
	private JButton jButtonNext = null;
	private JLabel jLabeluser = null;
	private JTextField jTextFielduser = null;
	public static String[] block =null;
	public static String[] chackname1=null;
	final public static int DEFAULT_PORT = 5555;  
    private String host = MainPanel.ip;      
    int port=0;
    int s;
    int chak;
	public static Client client1;
	public static Client client3;
	public static String[] ans;
	private JButton jButtonHelp = null;
	
	public BlockCommit() {
		super();
		initialize();
	}

	/**
	 * This method initializes AcademicFrame 
	 */
	private void initialize() {
		this.setSize(1000, 720);
		this.setContentPane(getSub());
		this.setTitle("Block User");		
	}

	private JPanel getSub() {
		if (Sub == null) {
			
			ImageIcon imageBack = new ImageIcon("comp.jpg");
			jLabelBackground = new JLabel();
			jLabelBackground.setIcon(imageBack);
			jLabelBackground.setBounds(new Rectangle(-8, -25, 996, 720));
			jLabeluser = new JLabel();
			jLabeluser.setBounds(new Rectangle(158, 91, 198, 46));
			jLabeluser.setText("User name:");
			Sub = new JPanel();
			Sub.setLayout(null);
			Sub.setBackground(Color.CYAN);
			Sub.add(getJButtonBack(), null);
			Sub.add(getJButtonNext(), null);
			Sub.add(jLabeluser, null);
			Sub.add(getJTextFielduser(), null);
			Sub.add(getJButtonHelp(), null);
			Sub.add(jLabelBackground, null);


			
		}
		return Sub; 
	}

	/**
	 * This method initializes jButtonBack	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonBack() {
		if (jButtonBack == null) {
			jButtonBack = new JButton();
			jButtonBack.setBounds(new Rectangle(260, 565, 143, 68));
			jButtonBack.setText("BACK");
			jButtonBack.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					MainSystemManger NewSystem = new MainSystemManger();
					NewSystem.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
					NewSystem.setSize( 1000,720 ); // set frame size
					NewSystem.setResizable(true);
					NewSystem.setVisible( true ); // display frame
					BlockCommit.this.dispose();
				    
				}
			});
		}
		return jButtonBack;
	}

	/**
	 * This method initializes jButtonNext	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonNext() {
		if (jButtonNext == null) {
			jButtonNext = new JButton();
			jButtonNext.setBounds(new Rectangle(672, 560, 143, 68));
			jButtonNext.setText("NEXT");
			jButtonNext.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				/*
				 * we will first check if the user name is in our system 
				 * 	then we we will change the status of substate in the database to 
				 * 0 ( 1 is if the user isnt blocked)
				 */
				String name=jTextFielduser.getText();
				  if(!(name==null)){
				 client3 = new Client(host,DEFAULT_PORT);
				    chackname1=new String[5];
					chackname1[0]="chacknamevalid";
					chackname1[1]=name;
					client3.accept(chackname1);
					
					Object t = client3.getMsg();
					chackname1 = (String[])t;
					 chak=Integer.parseInt(chackname1[1]);
				    }

				      	if((chak==0)){

							Chackempty close = new Chackempty();
							close.jLabelMassage.setText("user name is not exist");
							close.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
							close.setSize( 380,217 ); // set frame size
							close.setResizable(true);
							close.setVisible( true ); 
					    	
						    s =1;
					         }
					
					
					
		           if(((name!=null)&&(s==0))){
				
					
					    client1 = new Client(host,DEFAULT_PORT);
					    block = new String[2];
					    block[0] = "block";						
					    block[1] = name;
					    client1.accept(block);
						Object p = client1.getMsg();
						ans = (String[])p;
						
						if (ans[1].equals("1"))
						{	
							Closecomsec close = new Closecomsec();
						    close.jLabelMassage.setText("user blocked");
						    close.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						    close.setSize( 380,217 ); // set frame size
						    close.setResizable(true);
						    close.setVisible( true ); 
						}
						
					 
					   
					}
				
				    
				}
			});
		
		}
		return jButtonNext;
	}

	/**
	 * This method initializes jTextFielduser	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFielduser() {
		if (jTextFielduser == null) {
			jTextFielduser = new JTextField();
			jTextFielduser.setBounds(new Rectangle(404, 93, 192, 42));
		}
		return jTextFielduser;
	}

	/**
	 * This method initializes jButtonHelp	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonHelp() {
		if (jButtonHelp == null) {
			jButtonHelp = new JButton();
			jButtonHelp.setBounds(new Rectangle(100, 565, 143, 68));
			jButtonHelp.setText("Help");
			jButtonHelp.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					HelpFrame HFrame = new HelpFrame();

					HFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
					HFrame.setSize( 600,720 ); // set frame size
					HFrame.setResizable(false);
					HFrame.setVisible( true ); // display frame
				}
			});
		}
		return jButtonHelp;
	}

	
}  //  